home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / RCS / free.c,v < prev    next >
Encoding:
Text File  |  1991-12-05  |  5.3 KB  |  263 lines

  1. head     1.6;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.6.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.6
  10. date     89.12.11.13.39.44;  author rab;  state Exp;
  11. branches 1.6.1.1;
  12. next     1.5;
  13.  
  14. 1.5
  15. date     89.03.22.00.47.10;  author rab;  state Exp;
  16. branches ;
  17. next     1.4;
  18.  
  19. 1.4
  20. date     88.07.25.11.10.57;  author ouster;  state Exp;
  21. branches ;
  22. next     1.3;
  23.  
  24. 1.3
  25. date     88.07.25.10.48.06;  author ouster;  state Exp;
  26. branches ;
  27. next     1.2;
  28.  
  29. 1.2
  30. date     88.06.18.17.17.38;  author ouster;  state Exp;
  31. branches ;
  32. next     1.1;
  33.  
  34. 1.1
  35. date     88.05.20.15.49.30;  author ouster;  state Exp;
  36. branches ;
  37. next     ;
  38.  
  39. 1.6.1.1
  40. date     91.12.04.21.27.04;  author kupfer;  state Exp;
  41. branches ;
  42. next     ;
  43.  
  44.  
  45. desc
  46. @@
  47.  
  48.  
  49. 1.6
  50. log
  51. @Declared free() as void for lint.
  52. @
  53. text
  54. @/* 
  55.  * free.c --
  56.  *
  57.  *    Source code for the "free" library procedure.  See memInt.h for
  58.  *    overall information about how the allocator works.
  59.  *
  60.  * Copyright 1985, 1988 Regents of the University of California
  61.  * Permission to use, copy, modify, and distribute this
  62.  * software and its documentation for any purpose and without
  63.  * fee is hereby granted, provided that the above copyright
  64.  * notice appear in all copies.  The University of California
  65.  * makes no representations about the suitability of this
  66.  * software for any purpose.  It is provided "as is" without
  67.  * express or implied warranty.
  68.  */
  69.  
  70. #ifndef lint
  71. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/free.c,v 1.5 89/03/22 00:47:10 rab Exp Locker: rab $ SPRITE (Berkeley)";
  72. #endif /* not lint */
  73.  
  74. #include <stdio.h>
  75. #include <stdlib.h>
  76. #include "memInt.h"
  77.  
  78. /*
  79.  * Variable that indicates whether or not it's acceptable to free
  80.  * a block that's already free (for some reason, many UNIX programs,
  81.  * damn them to hell, do this).
  82.  */
  83.  
  84. int    memAllowFreeingFree = 1;
  85.  
  86. /*
  87.  * ----------------------------------------------------------------------------
  88.  *
  89.  * free --
  90.  *
  91.  *      Return a previously-allocated block of storage to the free pool.
  92.  *
  93.  * Results:
  94.  *      None.
  95.  *
  96.  * Side effects:
  97.  *      The storage pointed to by blockPtr is marked as free and returned
  98.  *    to the free pool.  Nothing in the bytes pointed to by blockPtr is
  99.  *    modified at this time:  no change will occur until at least the
  100.  *    next call to malloc or realloc.  This means that callers may use
  101.  *    the contents of a block for a short time after free-ing it (e.g.
  102.  *    to read a "next" pointer).
  103.  *
  104.  * ----------------------------------------------------------------------------
  105.  */
  106.  
  107. ENTRY
  108. #ifdef lint
  109. void
  110. #endif
  111. free(blockPtr)
  112.     register Address blockPtr;    /* Pointer to storage to be freed.  Must
  113.                  * have been the return value from Mem_Alloc
  114.                  * at some previous time.  */
  115. {
  116.     register int  admin;
  117.     register int  index;
  118.     register int  size;
  119.  
  120.     LOCK_MONITOR;
  121.  
  122. #ifdef MEM_TRACE
  123.     mem_NumFrees++;
  124. #endif
  125.  
  126.     if (!memInitialized) {
  127.         panic("Mem_Free: allocator not initialized!\n");
  128.     return;        /* should never get here */
  129.     }
  130.     if (blockPtr == NULL) {
  131.     UNLOCK_MONITOR;
  132.     return;
  133.     }
  134.  
  135.     /* 
  136.      *  Make sure that this block bears some resemblance to a
  137.      *  well-formed storage block.
  138.      */
  139.  
  140.     blockPtr -= sizeof(AdminInfo);
  141.     admin = GET_ADMIN(blockPtr);
  142.     if (!IS_IN_USE(admin)) {
  143.     if (IS_DUMMY(admin)) {
  144.         panic("Mem_Free: storage block corrupted\n");
  145.     }
  146.     if (!memAllowFreeingFree) {
  147.         panic("Mem_Free: storage block already free\n");
  148.     }
  149.     UNLOCK_MONITOR;
  150.     return;
  151.     }
  152.  
  153.     /* This procedure is easier for un-binned blocks (those without the
  154.      * DUMMY bit set) than for the binned ones.  If un-binned, just clear
  155.      * the use bit and record how many bytes were freed, for use later
  156.      * when deciding whether or not to allocate more storage.
  157.      */
  158.  
  159.     size = SIZE(admin);
  160.     index = BLOCKSIZE_TO_INDEX(size);
  161.     if (!IS_DUMMY(admin)) {
  162.     SET_ADMIN(blockPtr, MARK_FREE(admin));
  163.     memBytesFreed += SIZE(admin);
  164.     } else {
  165.     /* 
  166.      * For small blocks, add the block back onto its free list.
  167.      */
  168.  
  169.     index = BLOCKSIZE_TO_INDEX(SIZE(admin));
  170.     SET_ADMIN(blockPtr, MARK_FREE((int) memFreeLists[index]));
  171.     memFreeLists[index] = blockPtr;
  172.     }
  173.  
  174. #ifdef MEM_TRACE
  175.     MemDoTrace(FALSE, blockPtr, Mem_CallerPC(), size);
  176. #endif MEM_TRACE
  177.  
  178.     UNLOCK_MONITOR;
  179. }
  180. @
  181.  
  182.  
  183. 1.6.1.1
  184. log
  185. @Initial branch for Sprite server.
  186. @
  187. text
  188. @d18 1
  189. a18 1
  190. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/free.c,v 1.6 89/12/11 13:39:44 rab Exp $ SPRITE (Berkeley)";
  191. @
  192.  
  193.  
  194. 1.5
  195. log
  196. @*** empty log message ***
  197. @
  198. text
  199. @d18 1
  200. a18 1
  201. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/free.c,v 1.4 88/07/25 11:10:57 ouster Exp Locker: rab $ SPRITE (Berkeley)";
  202. d55 3
  203. @
  204.  
  205.  
  206. 1.4
  207. log
  208. @Lint.
  209. @
  210. text
  211. @d18 2
  212. a19 2
  213. static char rcsid[] = "$Header: free.c,v 1.3 88/07/25 10:48:06 ouster Exp $ SPRITE (Berkeley)";
  214. #endif not lint
  215. d22 1
  216. @
  217.  
  218.  
  219. 1.3
  220. log
  221. @Change free return type to match UNIX.
  222. @
  223. text
  224. @d18 1
  225. a18 1
  226. static char rcsid[] = "$Header: free.c,v 1.2 88/06/18 17:17:38 ouster Exp $ SPRITE (Berkeley)";
  227. d21 1
  228. @
  229.  
  230.  
  231. 1.2
  232. log
  233. @Use panic instead of Sys_Panic.
  234. @
  235. text
  236. @d18 1
  237. a18 1
  238. static char rcsid[] = "$Header: free.c,v 1.1 88/05/20 15:49:30 ouster Exp $ SPRITE (Berkeley)";
  239. d52 1
  240. a52 1
  241. ENTRY void
  242. @
  243.  
  244.  
  245. 1.1
  246. log
  247. @Initial revision
  248. @
  249. text
  250. @d18 1
  251. a18 1
  252. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  253. d69 1
  254. a69 1
  255.         MemPanic("Mem_Free: allocator not initialized!\n");
  256. d86 1
  257. a86 1
  258.         MemPanic("Mem_Free: storage block corrupted\n");
  259. d89 1
  260. a89 1
  261.         MemPanic("Mem_Free: storage block already free\n");
  262. @
  263.